@extends('default.layouts.adminPublic')
@section('title', '防CC列表')
@section('headcss')
    @parent
    <link rel="stylesheet" href="{{asset('/default/css/admin/indexList.css')}}">
    @endsection
    @section('content')
            <!--导航开始-->
    <div class="crumb_warp">
        <i class="fa fa-home"></i> <a href="{{url('admin/links')}}">首页</a> &raquo; 防CC列表
    </div>
    <!--导航结束-->
    <!--结果集标题与导航组件 开始-->
    <div class="con">
        <div class="conMain">
            <div class="result_wrap" style="height:140px;">
                <div class="search">
                    <form name="Formso" id="Formso" action="{{url('admin/cc_list')}}" method="post">
                        {{csrf_field()}}
                        <span>关键字：</span>
                        <span><input name="keyword" class="keyword" id="keyword" placeholder="请输入访问的IP"
                                     type="text"></span>
                        <span><input name="submit" class="skeyword" value="搜索" type="submit"></span>
                    </form>
                    <div class="smart">
                        <ul>
                            <li class="title">访问类型：</li>
                            <li><a href="{{url('admin/cc_list?minute=1')}}">1分钟内</a></li>
                            <li><a href="{{url('admin/cc_list?minute=3')}}">3分钟内</a></li>
                            <li><a href="{{url('admin/cc_list?minute=10')}}">10分钟内</a></li>
                            <li><a href="{{url('admin/cc_list?minute=30')}}">30分钟内</a></li>
                            <li><a href="{{url('admin/cc_list?minute=60')}}">1小时内</a></li>
                            <li><a href="{{url('admin/cc_list?minute=720')}}">12小时内</a></li>
                            <li><a href="{{url('admin/cc_list?minute=1440')}}">1天内</a></li>
                            <li><a href="{{url('admin/cc_list?minute=10080')}}">7天内</a></li>
                            <li><a href="{{url('admin/cc_list?minute=21600')}}">半个月内</a></li>
                            <li><a href="{{url('admin/cc_list?minute=43200')}}">一个月内</a></li>
                        </ul>
                        <div class="message"><p>
                                目前共查找到<strong>{{$trafficStatistics->total()}}</strong>个记录！且每页显示防CC记录{{$trafficStatistics->perPage()}}
                                个。<a onclick="clearData()">清空所有数据信息</a></p> </div>
                    </div>
                </div>
            </div>
            <div class="manage">
                @include('flash::message')
            </div>
            <div class="conInfo">
                <form name="thisForm" id="thisForm" action="" method="post">
                    {{csrf_field()}}
                    <div class="conList" id="conList">
                        <dl class="one">
                            <dt><input name="selectall" type="checkbox" value="1" onclick="CheckAll(this)"/></dt>
                            <dd class="cc1">访问IP</dd>
                            <dd class="cc2">访问Url</dd>
                            {{--<dd class="cc3">访问浏览器</dd>--}}
                            <dd class="cc4">访问次数</dd>
                            <dd class="cc5">访问操作</dd>
                        </dl>
                        @if($trafficStatistics->count() > 0 )
                            @foreach($trafficStatistics as $v)
                                <dl id="list{{$v->id}}">
                                    <dt><input name="selected_id[]" type="checkbox" value="{{$v->id}}"/></dt>
                                    <dd class="cc1"><a href="{{url('admin/cc_all_info?ip='.$v->ip)}}" target="_blank">{{str_limit($v->ip,24)}}</a>
                                    </dd>
                                    <dd class="cc2">{{str_limit($v->url,40)}}</dd>
                                    {{--<dd class="cc3">{{$v->header}}</dd>--}}
                                    <dd class="cc4">{{$v->ccc}}</dd>
                                    <dd class="cc5">
                                        <span><a onclick="addIp('{{$v->ip}}')">添加黑名单</a></span>
                                        <span><a onclick="delIp('{{$v->ip}}')">删除黑名单</a></span>
                                    </dd>
                                </dl>
                            @endforeach
                        @else
                            <div class="nullcon">对不起！没有防CC记录！</div>
                        @endif
                        <dl class="last">
                            <dt>
                                <input name="selectall" id="selectall" type="checkbox" value="1"
                                       onclick="CheckAll(this)"/>
                                <label for="selectall">全选</label>
                            </dt>
                        </dl>
                    </div>
                </form>
                <div class="page_list" style="width: 100%; float: left; margin-top:15px;">
                    {!! $trafficStatistics->appends($appends)->links() !!}
                </div>
            </div>

            <div class="stopper" style="margin-top:10px; border-top: 1px solid #e5e5e5"></div>
        </div>
    </div>
    <!--结果集标题与导航组件 结束-->
@endsection

@section('footerjs')
    @parent
    <script>
        var sign = true;
        //全选中与全不选中职位资料
        function CheckAll(form){
            if(form.checked == true){
                for(var i = 0; i < document.thisForm.elements.length; i++){
                    var e = document.thisForm.elements[i];
                    if(e.name == 'selectedid' || e.name == 'selected_id[]' || e.name == 'selectall')
                        e.checked = true;
                }
            }else{
                for(var i = 0; i < document.thisForm.elements.length; i++){
                    var e = document.thisForm.elements[i];
                    if(e.name == 'selectedid' || e.name == 'selected_id[]' || e.name == 'selectall')
                        e.checked = false;
                }
            }
        }

        //添加到黑名单
        function addIp(ip){
            layer.confirm('您确定要添加这个IP到黑名单吗？', {
                btn: ['确定', '取消'] //按钮
            }, function(){
                if(sign == true){
                    sign = false;
                    $.post("/admin/cc_add", {'ip': ip, '_token': "{{csrf_token()}}"}, function(data){
                        if(data.status == 0){
                            layer.msg(data.msg, {icon: 6, time: 1500});
                        }else{
                            layer.msg(data.msg, {icon: 5, time: 1500});
                        }
                        sign = true;
                    });
                }
            });
        }
        //添加到黑名单
        function delIp(ip){
            layer.confirm('您确定要删除这个IP吗？', {
                btn: ['确定', '取消'] //按钮
            }, function(){
                if(sign == true){
                    sign = false;
                    $.post("/admin/cc_del", {'ip': ip, '_token': "{{csrf_token()}}"}, function(data){
                        if(data.status == 0){
                            layer.msg(data.msg, {icon: 6, time: 1500});
                        }else{
                            layer.msg(data.msg, {icon: 5, time: 1500});
                        }
                        sign = true;
                    });
                }
            });
        }

        //添加到黑名单
        function clearData(ip){
            layer.confirm('您确定要清空全部ip数据吗？', {
                btn: ['确定', '取消'] //按钮
            }, function(){
                if(sign == true){
                    sign = false;
                    $.post("/admin/cc_clear", {'_token': "{{csrf_token()}}"}, function(data){
                        if(data.status == 0){
                            layer.msg(data.msg, {icon: 6, time: 1500});
                            location='/admin/cc_list';
                        }else{
                            layer.msg(data.msg, {icon: 5, time: 1500});
                        }
                        sign = true;
                    });
                }
            });
        }

    </script>
@endsection